package com.mht.cfa.server.controller;

import com.mht2017.common.consts.ResultCode;
import com.mht2017.common.response.ErrorMessageResponse;
import com.mht2017.common.response.IResponse;
import com.mht2017.common.response.SuccessMessageResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/demo")
public class DemoController {
    private static final Logger LOGGER = LoggerFactory.getLogger(DemoController.class);
    private static final String ACTION_NAME = "测试接口控制器";

    /**
     * 测试返回接口
     * @return
     */
    @RequestMapping(value = "/getStringByUrl", method = {RequestMethod.GET})
    @ResponseBody
    public IResponse getStringUrl() {
        try {
            return new SuccessMessageResponse("success return back!");
        } catch (Exception e) {
            LOGGER.error(String.format("%s - %s", ACTION_NAME, e.getMessage()), e);
            return new ErrorMessageResponse(ResultCode.OTHER_ERROR.getCode(), ResultCode.OTHER_ERROR.getName());
        }
    }

    /**
     * 测试返回接口
     * @return
     */
    @RequestMapping(value = "/getJsonString", method = {RequestMethod.POST}, consumes = "application/json")
    @ResponseBody
    public IResponse getString() {
        try {
            return new SuccessMessageResponse("success return!");
        } catch (Exception e) {
            LOGGER.error(String.format("%s - %s", ACTION_NAME, e.getMessage()), e);
            return new ErrorMessageResponse(ResultCode.OTHER_ERROR.getCode(), ResultCode.OTHER_ERROR.getName());
        }
    }

}
